package com.neuedu.corejava.ch6.game;

public class GameRole {
    
	//类指的是类型，是由多个具有相同特征的实物（对象）
	
	//名字
	private String name; 
	//武器
	private String weapon;
	//战斗力
	private String attack;
	//耐力
	private String endurance;
	
	public static void main(String[] args){
		//类与对象的关系
		//对象抽象出类，类实例化为对象
		GameRole sun = new GameRole("孙悟空","金箍棒","3","3");
		sun.fighting();
		sun.defense();
		GameRole tang= new GameRole("唐僧","无","3","3");
		tang.fighting();
		tang.defense();		
		GameRole zhu = new GameRole("猪八戒","耙子","3","3");
		zhu.fighting();
		zhu.defense();
		GameRole sha = new GameRole("沙僧","月牙铲","3","3");
		sha.fighting();
		sha.defense();
		
		GameRole rGameRole = null;
		for (int i = 0; i < 10000000; i++) {
			//在循环外，超出声命周期的对象都是垃圾，可以进行回收
			GameRole gameRole = new GameRole();
			
			rGameRole = new GameRole();
		}
		System.gc();//通知垃圾回收器回收垃圾；jvm收到通知后，会调度gc进行内存回收。
	    //内存泄露：当有一个堆内存一直有栈指针执行它，这块堆内存则无法进行回收，这种情况称为内存泄露
	}
	
	
	//一个类编写了带参构造方法后，会屏蔽默认的空参构造方法
	//如果需要使用空参构造方法，必须显式编写一个
	
	public GameRole(String name, String weapon, String attack, String endurance) {
		super();
		this.name = name;
		this.weapon = weapon;
		this.attack = attack;
		this.endurance = endurance;
	}
	
	

	public GameRole() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getWeapon() {
		return weapon;
	}
	public void setWeapon(String weapon) {
		this.weapon = weapon;
	}
	public String getAttack() {
		return attack;
	}
	public void setAttack(String attack) {
		this.attack = attack;
	}
	public String getEndurance() {
		return endurance;
	}
	public void setEndurance(String endurance) {
		this.endurance = endurance;
	}
	
	//战斗
	public void fighting(){
		System.out.println(name+" 在战斗");
	}
	
	//防御
	public void defense(){
		System.out.println(name+" 在防御");
	}
	

}
